package com.lanou3g.zjl.chating.home.chatwindow.child;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;

import com.lanou3g.zjl.chating.R;


/**
 * Created by dllo on 15/11/23.
 * 底部的菜单view
 */
public class ChatWindowFrgMenu extends RelativeLayout{
    private Context context;
    private EditText chat_Et;
    private Button chat_Btn;
    private Animation round;

    public ChatWindowFrgMenu(Context context) {
        super(context);
        initView(context);
    }

    public ChatWindowFrgMenu(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public ChatWindowFrgMenu(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        this.context = context;
        // 加载 底部输入和菜单 布局
        LayoutInflater.from(context).inflate(R.layout.chatwindowfrg_menu, this);
        chat_Et = (EditText) findViewById(R.id.chat_Et);
        chat_Btn = (Button) findViewById(R.id.chat_Btn);
        chat_Et.addTextChangedListener(textWatcher);

        round = AnimationUtils.loadAnimation(context, R.anim.cw_round);
        round.setFillAfter(true); // 设置终止填充
    }

    private String str;
    private TextWatcher textWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            str = chat_Et.getText().toString().trim();
            if (str != null && str.length() > 0) {
                chat_Btn.setBackgroundResource(R.mipmap.send_msg);
            } else {
                chat_Btn.setBackgroundResource(R.mipmap.voice);
            }
        }
    };


}
